package com.iss.examsys.ejb;

import com.iss.examsys.entity.ExamSession;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author Quek Ting Hong
 */
@Stateless
public class ExamSessionBean {
    @PersistenceContext EntityManager em;

    public void create(ExamSession entity){
        em.persist(entity);
    }
    
    public void edit(ExamSession entity) {
        em.merge(entity);
    }
    
    public ExamSession findById(Long id){        
        ExamSession entity = em.find(ExamSession.class, id);        
        return entity;
    }
    
     public List<ExamSession> findAll(){
        TypedQuery<ExamSession> result = em.createNamedQuery("ExamSession.findAll", ExamSession.class);        
        return result.getResultList();
    } 
     
     public List<ExamSession> findByName(String name){
        TypedQuery<ExamSession> result = em.createNamedQuery("ExamSession.findByName", ExamSession.class);
        result.setParameter("name", name);
        return result.getResultList();
    }
     
    public List<ExamSession> findByLocation(String location){
        TypedQuery<ExamSession> result = em.createNamedQuery("ExamSession.findByLocation", ExamSession.class);
        result.setParameter("location", location);
        return result.getResultList();
    }
    
    public List<ExamSession> findByModuleIds(List<Long> moduleIds){
        TypedQuery<ExamSession> result = em.createNamedQuery("ExamSession.findByModuleIds", ExamSession.class);
        result.setParameter("moduleIds", moduleIds);
        return result.getResultList();
    }
}
